//****************************************************************************
//Copyright (C) 2005 Adobe Systems, Inc. All Rights Reserved.
//The following is Sample Code and is subject to all restrictions on
//such code as contained in the End User License Agreement accompanying
//this product.
//****************************************************************************

/**
 * class used to create a Sound Object, load media into it, play, pause, etc...
*/

class SoundPlayer extends ImageViewer {
  
	//---------------------------------------------- Properties
  	
  	private var state:Boolean;
  	private var soundObject:Object;
  	private var currentDur:Number;
  	private var currentPos:Number;
  	private var startTime:Number;
  
	//---------------------------------------------- Methods
	
	/**
	 * constructor method
	 */
  	public function SoundPlayer (target:MovieClip, 
                               depth:Number, 
                               x:Number, 
                               y:Number, 
                               w:Number, 
                               h:Number,
                               borderThickness:Number,
                               borderColor:Number,
                               background:Boolean) {
  		super(target, depth, x, y, w, 100, borderThickness, borderColor, background);
  		soundObject = new Sound();				// create a Sound Object
  		soundObject.path = this;					// set path to this class
  		displayStats();							// display the position over duration
  	}

  	/**
  	 * loadSound method
  	 * 
  	 */
	public function loadSound (URL:String):Void { 
  		soundObject.onLoad = function() {			// create callback
  			this.path.soundPlay();				// start playing
  			this.path.setState(true);				// set the state to true for playing
  		}
  		soundObject.loadSound(URL, false);		// load event sound, streaming not supported
  	}
  	
  	/**
  	 * soundStop method
  	 */
  	public function soundStop():Void {
  		soundObject.stop();
  	}
  
  	/**
  	 * soundPlay method, offset param not supported with device sound
  	 */
  	public function soundPlay():Void {
  		soundObject.start();
    	}
  	
  	/**
  	 * method used to populate textfield on screen
  	 */
  	private function displayStats(message:String):Void {
  		createMessage("Playing Audio...\n\nUse the right soft key\nto stop/play");
  	}
  	
  	/**
  	 * setState method
  	 */
  	public function setState(newState:Boolean):Void {
  		state = newState;	
  	}
  	
  	/**
  	 * getState method
  	 */
  	public function getState():Boolean {
  		return state;
  	}
  
  	/**
  	 * destroy method
  	 */
	public function destroy():Void {
		soundObject.stop();
		delete soundObject;
		super.destroy();
  	}
}